package autofactory;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DBtools.UserBO;
import abstractclass.PageManagerAbstract;
import page.PageManagerMainFactory;
import model.UserInfoBase;
import model.UserModel;
import tools.NameTag;
import iinterface.UpdateAble;

public class UpdateHeartBeatPage implements UpdateAble{

	@Override
	public boolean build(HttpServletRequest req, HttpServletResponse resp) {
		// TODO Auto-generated method stub
		String username = (String) req.getSession().getAttribute("username");
		UserInfoBase info = (UserInfoBase) req.getSession().getAttribute(username);
		if(info==null){
			return false;
		}
		if(!info.pageManeger.getName().equals(NameTag.HEARTBEAT_NAME_TAG)){
			return false;
		}
		
		
		PageManagerMainFactory factory = new PageManagerMainFactory();
		UserModel model = new UserModel();
		UserBO bo = new UserBO();
		List list = bo.find(username);
		HashMap<String, Object> map = (HashMap<String, Object>) list.get(0);
		model.user = username;
		model.userlevel = (int) map.get("userlevel");
		info.pageManeger = (PageManagerAbstract) factory.getPageManager(model);
		return true;

	}

}
